import {  isFunction } from 'lodash';
import { ElMessage } from "element-plus";
/**
 * 消息提示函数
 */
const message = (message, params) => {
  if(!message)message='操作成功';
  if (!params) {
    return ElMessage({
      message,
      customClass: "wd-message"
    });
  } else {
    const {
      icon,
      type = "info",
      dangerouslyUseHTMLString = false,
      customClass = "antd",
      duration = 2000,
      showClose = false,
      center = false,
      offset = 20,
      appendTo = document.body,
      grouping = false,
      onClose
    } = params;

    return ElMessage({
      message,
      type,
      icon,
      dangerouslyUseHTMLString,
      duration,
      showClose,
      center,
      offset,
      appendTo,
      grouping,
      customClass: customClass === "antd" ? "pure-message" : "",
      onClose: () => (isFunction(onClose) ? onClose() : null)
    });
  }
};

/**
 * 关闭所有 `Message` 消息提示函数
 */
const closeAllMessage = () => ElMessage.closeAll();

export { message, closeAllMessage };
